//
//  Tool.m
//  YaoHeAPP
//
//  Created by mac on 15/11/25.
//  Copyright (c) 2015年 mac. All rights reserved.
//

#import "Tool.h"
#import "HearderVC.h"
#import "ShopingCar.h"
#import "IssueVC.h"
#import "OrderVC.h"
#import "MySelfVC.h"
#import "xianhuoVC.h"
@implementation Tool



//沙盒路径
+(NSString *)getDocumentsPath
{
    NSString *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];

    return docPath;
}

//将字典转化成json字符串
+(NSString*)dictionary:(NSDictionary*)dic
{
    NSData*jsonData=[NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:nil];
    NSString*stringJson=[[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
    NSString*newString = [stringJson stringByReplacingOccurrencesOfString:@" " withString:@""];
    return newString;
}

//进入主界面
+(void)gotoMain:(NSInteger)awidth nameindex:(NSInteger)row
{
    UITabBarController*tabController=[[UITabBarController alloc]init];
    tabController.tabBar.barStyle=UIBarStyleBlackOpaque;
    
//    UIImageView*biaoqian=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"np_numberpicker_selection_divider"]];
//    biaoqian.frame=CGRectMake(0, -0.5, awidth, 1);
//    [tabController.tabBar addSubview:biaoqian];
    
    
    UIView *linview=[[UIView alloc]initWithFrame:CGRectMake(0, -0.5, awidth, 0.5)];
    linview.backgroundColor=[UIColor colorWithRed:204/255.0 green:204/255.0 blue:204/255.0  alpha:1];
    [tabController.tabBar addSubview:linview];
    
    tabController.tabBar.barTintColor=[UIColor colorWithRed:247.f/255.f green:247.f/255.f blue:247.f/255.f alpha:1];
    UIColor*bgcolor=[UIColor whiteColor];
    UIColor*tabbarColor=[bgcolor colorWithAlphaComponent:0.96];
    tabController.tabBar.backgroundColor=tabbarColor;
    
    
    //定义分栏的 选中 不选中 字体颜色
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                       [UIColor colorWithRed:99.f/255.f green:103.f/255.f blue:104.f/255.f alpha:1], UITextAttributeTextColor,
                                                       nil] forState:UIControlStateNormal];
    UIColor *titleHighlightedColor = [UIColor colorWithRed:73.f/255.f green:192.f/255.f blue:219.f/255.f alpha:1];
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                       titleHighlightedColor, UITextAttributeTextColor,
                                                       nil] forState:UIControlStateSelected];
    //首页
    HearderVC*headVC=[HearderVC new];
    headVC.tabBarItem.title=@"首页";

    headVC.tabBarItem.image=[UIImage imageNamed:@"home"];
    
    UIImage *headVCImageSel = [UIImage imageNamed:@"home_hr"];
    headVCImageSel = [headVCImageSel imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    headVC.tabBarItem.selectedImage=headVCImageSel;

    
    UINavigationController*navcHead=[[UINavigationController alloc]initWithRootViewController:headVC];

    //求购页
    ShopingCar*shopVC=[ShopingCar new];
    shopVC.tabBarItem.title=@"求购";
    shopVC.tabBarItem.image=[UIImage imageNamed:@"buy"];
    UIImage *shopVCImageSel = [UIImage imageNamed:@"buy_hr"];
    shopVCImageSel = [shopVCImageSel imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    shopVC.tabBarItem.selectedImage=shopVCImageSel;
    UINavigationController*navcShop=[[UINavigationController alloc]initWithRootViewController:shopVC];

    
    
    UIImageView*coreImage=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"ic_top_half"]];
    //    coreImage.backgroundColor=[UIColor whiteColor];
    coreImage.frame=CGRectMake(awidth/2-25, -11, 50, 11.5);
    [tabController.tabBar addSubview:coreImage];
    
    //发布求购页
    IssueVC*issueVC=[IssueVC new];
    UIImageView *addImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Release_for"]];
    addImage.alpha=1;

    addImage.frame=CGRectMake(awidth/2-25, -6, 50, 50);
    [tabController.tabBar addSubview:addImage];
    UINavigationController*navcIssue=[[UINavigationController alloc]initWithRootViewController:issueVC];

    
    //订单页
//    OrderVC*orderVC=[OrderVC new];
//    orderVC.tabBarItem.title=@"订单";
//    orderVC.tabBarItem.image=[UIImage imageNamed:@"order"];
//    UINavigationController*navcOrder=[[UINavigationController alloc]initWithRootViewController:orderVC];
    
    //信用航现货
    xianhuoVC*xhvc=[xianhuoVC new];
    xhvc.tabBarItem.title=@"现货";
    xhvc.tabBarItem.image=[UIImage imageNamed:@"Spot-goods"];
    
    UIImage *xhvcImageSel = [UIImage imageNamed:@"Spot-goods_hr"];
    xhvcImageSel = [xhvcImageSel imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    xhvc.tabBarItem.selectedImage=xhvcImageSel;

    UINavigationController*navcOrder=[[UINavigationController alloc]initWithRootViewController:xhvc];

    
    
    //我的个人页面
    MySelfVC*myselfV=[MySelfVC new];
    myselfV.tabBarItem.title=@"我的";
    myselfV.tabBarItem.image=[UIImage imageNamed:@"Center"];
    UIImage *myselfVImageSel = [UIImage imageNamed:@"Center_hr"];
    myselfVImageSel = [myselfVImageSel imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    myselfV.tabBarItem.selectedImage=myselfVImageSel;
    
    UINavigationController*navcMyself=[[UINavigationController alloc]initWithRootViewController:myselfV];

    //导航条数组
    NSArray*navcArray=[NSArray arrayWithObjects:navcHead,navcShop,navcIssue,navcOrder,navcMyself ,nil];
   
    tabController.viewControllers=navcArray;
    tabController.selectedIndex=row;
    UIWindow *window = [UIApplication sharedApplication].delegate.window;
    window.rootViewController = tabController;
}

@end

